<?php

class Application_Form_User extends Zend_Form
{
    private $view;
    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
        $this->setAttrib("id","form-adduser");
        $this->view = Zend_Layout::getMvcInstance()->getView();
        
        // create id element
        $id = $this->createElement("hidden","idusers");
        $id->setDecorators(array("ViewHelper"));
        $this->addElement($id);
        
        //create element username
        $username = $this->createElement("text","username");
        $username->setLabel("Tên tài khoản")
                     ->setRequired()
                     ->addValidators(array(
                        array("NotEmpty",false,array("messages"=>array('isEmpty'=>"Tên tài khoản không được để trống."))),
                     ))
                     ->setAttrib("size","60");            
        $this->addElement($username);
        
        //create element groups_id
        $groups_id = $this->createElement("select","groups_id");
        $groups_id->setLabel("Thuộc nhóm")
                  ->setRequired()
                 ->addValidators(array(
                    array("GreaterThan",false,array("min"=>0,"messages"=>array('notGreaterThan'=>"Phải xác định nhóm của tài khoản mới!"))),
                 ));            
        $this->addElement($groups_id);
        
        //create element password
        $password = $this->createElement("password","password");
        $password->setLabel("Mật khẩu")
                     ->setAttrib("size","60");            
        $this->addElement($password);
        
        //create element repassword
        $repassword = $this->createElement("password","repassword");
        $repassword->setLabel("Nhập lại mật khẩu")
                     ->setAttrib("size","60");            
        $this->addElement($repassword);
        
        //create element image
        $image = $this->createElement("file","user_image");
        $image->setLabel("Hình ảnh đại diện")
              ->addValidators(array(
                'Extension' => array(
                    "jpg,jpeg,png,gif", 
                    'messages'=>array(
                        'fileExtensionFalse'=>"Hình '%value%' không đúng dạng quy định(.jpg|.jpeg|.png|.gif)."
                    )
                ),
            ))->setDestination(APPLICATION_PATH."/../public/images/profile/");
        $this->addElement($image);
        
         // create group
       $this->addDisplayGroup(array(
            $username,
            $password,
            $repassword,
            $groups_id,
            $image
       ),"detail",array('class'=>'display-group'));
       
       
        //create element fullname
        $fullname = $this->createElement("text","fullname");
        $fullname->setLabel("Họ tên")
                 ->setAttrib("size","60");            
        $this->addElement($fullname);
        
        //create element email
        $email = $this->createElement("text","email");
        $email->setLabel("Email")
                 ->setAttrib("size","60");            
        $this->addElement($email);
        
        
        //create element address
        $address = $this->createElement("text","address");
        $address->setLabel("Địa chỉ")
                 ->setAttrib("size","60");            
        $this->addElement($address);
        
        //create element $phone
        $phone = $this->createElement("text","phone");
        $phone->setLabel("Điện thoại")
                 ->setAttrib("size","60");            
        $this->addElement($phone);
        
        // create group
       $this->addDisplayGroup(array(
            $fullname,
            $email,
            $address,
            $phone
       ),"groupleft",array('class'=>'display-group'));
        
        //create element birthday
        $birthday = $this->createElement("text","birthday");
        $birthday->setLabel("Ngày sinh")
                 ->setAttrib("size","30")
                 ->setAttrib("readonly",true);            
        $this->addElement($birthday);
        
        //create element gender
        $gender = $this->createElement("select","gender");
        $gender->setLabel("Giới tính")
                ->setMultiOptions(array(0=>"Nam",1=>"Nữ"));       
        $this->addElement($gender);
        
        //create element $nickyahoo
        $nickyahoo = $this->createElement("text","nickyahoo");
        $nickyahoo->setLabel("Nick Yahoo")
                 ->setAttrib("size","50");            
        $this->addElement($nickyahoo);
        
        //create element $nickyahoo
        $nickskype = $this->createElement("text","nickskype");
        $nickskype->setLabel("Nick Skype")
                 ->setAttrib("size","50");            
        $this->addElement($nickskype);
        
        // create group
       $this->addDisplayGroup(array(
            $birthday,
            $gender,
            $nickyahoo, 
            $nickskype
       ),"groupright",array('class'=>'display-group'));
        
        
        // create submit button
        $submit = $this->createElement("submit","submit");
        $submit->setLabel("Thêm mới")
               ->setAttrib("class","btn btn-black");
        $this->addElement($submit);
        
        // create submit button
        $link = $this->view->url(array(
            'module'=>"admin",
            'controller'=>"user",
            'action'=>"index"
        ), null, true);
        $cancel = $this->createElement("button","cancel");
        $cancel->setLabel("Quay lại")
               ->setAttrib("class","btn btn-red")
               ->setAttrib("onclick","window.location='$link'");
        $this->addElement($cancel);  
        
        
        
    }
    
    
}

